package ge.telasi.tasks.ui.flowpermission;

import ge.telasi.tasks.model.Task;
import ge.telasi.tasks.ui.comp.ListModel;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

/**
 * @author dimitri
 */
public class TaskTypeList extends JList {
    static final List<Integer> ALL_TYPES;
    
    static {
        ALL_TYPES = new ArrayList<Integer>();
        ALL_TYPES.add(Task.TYPE_GENERAL);
    }

    public TaskTypeList() {
        TaskTypeListModel model = new TaskTypeListModel();
        model.setData(ALL_TYPES);
        setModel(model);
        setCellRenderer(new TaskTypeRenderer());
    }

    public Integer getSelection() {
        TaskTypeListModel model = (TaskTypeListModel) getModel();
        return model.getObjectAt(getSelectedIndex());
    }

    class TaskTypeListModel extends ListModel<Integer> {
    }

    class TaskTypeRenderer extends DefaultListCellRenderer {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof Integer) {
                int taskType = (Integer) value;
                setText(FlowPermissionDecorationUtils.getTaskTypeName(taskType));
                setIcon(FlowPermissionDecorationUtils.getTaskTypeIcon(taskType));
            }
            return this;
        }

    }

}
